package com.service;

import com.dao.PersonalJdbc;
import com.model.Personal;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class PersonalService {
    PersonalJdbc pj = new PersonalJdbc();
    public List<Personal> show() {
        List<Personal> list = new ArrayList<Personal>();
        ResultSet rs = pj.show();
        try {
            while (rs.next()) {
                int mid = rs.getInt("mid");
                String realname = rs.getString("realname");
                String sex =  rs.getString("sex");
                String city =  rs.getString("city");
                String number = rs.getString("number");
                String telephone = rs.getString("telephone");
                String email = rs.getString("email");
                Personal personal = new Personal(mid,realname,sex,city,number,telephone,email);
                list.add(personal);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }

    public Personal selectById(int id) throws SQLException {
        ResultSet rs = pj.selectById(id);
        Personal personal =null;
        while(rs.next()){
            String realname = rs.getString("realname");
            String sex =  rs.getString("sex");
            String city =  rs.getString("city");
            String number = rs.getString("number");
            String telephone = rs.getString("telephone");
            String email = rs.getString("email");
            personal = new Personal(rs.getInt("mid"),realname,sex,city,number,telephone,email);
        }

        return personal;
    }
    public Personal toupdate(String id) throws SQLException {
        ResultSet rs = pj.show();
        Personal personal = null;
        while (rs.next()) {
            String realname = rs.getString("realname");
            String sex =  rs.getString("sex");
            String city =  rs.getString("city");
            String number = rs.getString("number");
            String telephone = rs.getString("telephone");
            String email = rs.getString("email");
            personal = new Personal(rs.getInt(",mid"), realname,sex,city,number,telephone,email);
        }
        return personal;
    }
    public void update(String mid, String realname, String sex, String city,String number,String telephone, String email) {
        pj.update(mid,realname,sex,city,number,telephone,email);
    }
}
